package com.syl.starter.mp.generate;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.TemplateConfig;

/**
 * 后台管理专用生成器
 *
 * @author syl
 * @create 2019-11-08 10:07
 **/
public class AdminCodeGenerate extends SimpleCodeGenerate {

    /**
     * 以当前项目路径构造  最简单
     *
     * @param author 作者
     */
    public AdminCodeGenerate(String author) {
        super(author);
    }

    /**
     * 以当前项目路径构造
     *
     * @param author 作者
     * @param idType 主键生成策略
     */
    public AdminCodeGenerate(String author, IdType idType) {
        super(author, idType);
    }

    /**
     * 以当前项目路径构造
     *
     * @param author 作者
     * @param idType 主键生成策略
     * @param moreDataSource 是否多数据源
     */
    public AdminCodeGenerate(String author, IdType idType, boolean moreDataSource) {
        super(author, idType, moreDataSource);
    }

    /**
     * @param projectPath 目标项目路径
     * @param author 作者
     * @param idType 主键生成策略
     * @param moreDataSource 是否多数据源
     */
    public AdminCodeGenerate(String projectPath, String author, IdType idType, boolean moreDataSource) {
        super(projectPath, author, idType, moreDataSource);
    }

    @Override
    public void start() throws Exception {
        SuperCodeGenerate superCodeGenerate = getSuperCodeGenerate();
        TemplateConfig templateConfig = superCodeGenerate.getDefaultTemplateConfig();
        templateConfig.setService("/template/service.admin.java.vm");
        superCodeGenerate.setTemplateConfig(templateConfig);
        superCodeGenerate.start();
    }

    @Override
    public AdminCodeGenerate setProjectPath(String projectPath) {
        getSuperCodeGenerate().setProjectPath(projectPath);
        return this;
    }

    @Override
    public AdminCodeGenerate setTableNames(String... tableNames) {
        getSuperCodeGenerate().setTableNames(tableNames);
        return this;
    }

    /**
     * 设置去除表名称前缀
     * @param tablePrefixWipes
     * @return
     */
    @Override
    public AdminCodeGenerate setTablePrefixWipes(String... tablePrefixWipes) {
        getSuperCodeGenerate().setTablePrefixWipes(tablePrefixWipes);
        return this;
    }

    @Override
    public AdminCodeGenerate setDataSourceConfig(DataSourceConfig dataSourceConfig) {
        getSuperCodeGenerate().setDataSourceConfig(dataSourceConfig);
        return this;
    }

    /**
     * 设置包配置
     * @param packageConfig
     * @return
     */
    @Override
    public AdminCodeGenerate setPackageConfig(PackageConfig packageConfig) {
        getSuperCodeGenerate().setPackageConfig(packageConfig);
        return this;
    }

}
